package cn.itsource.exam.controller;

import cn.itsource.exam.domain.Login;
import cn.itsource.exam.domain.StudentInfo;
import cn.itsource.exam.domain.TeacherInfo;
import cn.itsource.exam.query.UserInfoQuery;
import cn.itsource.exam.service.StudentInfoService;
import cn.itsource.exam.service.TeacherInfoService;
import cn.itsource.exam.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by su on 2020/7/8.
 */
@RestController
@RequestMapping("/teacher")
public class TeacherInfoController {

    @Autowired
    private TeacherInfoService teacherInfoService;

    /**
     * 增加或修改老师
     * @param teacher
     */
    @RequestMapping(value = "modify",method = RequestMethod.POST)
    public  String modifyUser(@RequestBody TeacherInfo teacher, HttpServletRequest rq){
        Login info = (Login)rq.getSession().getAttribute(rq.getHeader("U-TOKEN"));
        return teacherInfoService.modifyUser(teacher,info.getName());
    }

    /**
     * 刪除用戶
     * @param id
     */
    @RequestMapping(value = "del",method = RequestMethod.POST)
    public String delUser(Long id, HttpServletRequest rq){
        Login info = (Login)rq.getSession().getAttribute(rq.getHeader("U-TOKEN"));
        return teacherInfoService.delUser(id, info.getName());
    }

    @RequestMapping(value = "batchdel",method = RequestMethod.POST)
    public String batchDelUser(String ids, HttpServletRequest rq){
        Login info = (Login)rq.getSession().getAttribute(rq.getHeader("U-TOKEN"));
        return teacherInfoService.batchDelUser(ids,info.getName());
    }

    /**
     * 根据主键获取用户
     * @param id
     * @return
     */
    @RequestMapping(value = "get",method = RequestMethod.GET)
    public TeacherInfo getUserById(Long id){
        return teacherInfoService.getUserById(id);
    }

    /**
     * 分页查询用户
     * @param paramIn
     * @return
     */
    @RequestMapping(value = "listpage",method = RequestMethod.POST)
    public PageList<TeacherInfo> getUserList(@RequestBody UserInfoQuery paramIn){
        return teacherInfoService.getUserList(paramIn);
    }

    /**
     * 查询所有老师
     * @return
     */
    @RequestMapping(value = "listall",method = RequestMethod.POST)
    public List<TeacherInfo> getUserList(){
        return teacherInfoService.getAllTeacherList();
    }
}
